package main

import "fmt"

type User struct {
	UserName    string
	UserPasswd  string
	UserAddress string
	UserAge     string
}

type System struct {
	SystemName string
	SystemUser map[string]User
}

func main() {
	sys1 := System{
		SystemName: "购物系统",
		SystemUser: map[string]User{},
	}
	sys2 := System{
		SystemName: "生鲜系统",
		SystemUser: map[string]User{},
	}
	for {
		fmt.Println("请选择你想进入的系统：\n1、购物系统\n2、生鲜系统\n按q退出")
		var systemchoice string
		fmt.Scan(&systemchoice)
		var sys System
		if systemchoice == "1" {
			sys = sys1
		} else if systemchoice == "2" {
			sys = sys2
		} else {
			fmt.Println("退出成功！")
			break
		}
		fmt.Println("欢迎进入", sys.SystemName)
		for {
			var name string
			var passwd string
			var address string
			var age string
			var choice string
			fmt.Println("请输入你的的选择：\n1、注册\n2、登录\n按q退出")
			fmt.Scan(&choice)
			if choice == "1" {
				fmt.Println("请输入用户名、密码和年龄")
				fmt.Println("请输入用户名：")
				fmt.Scan(&name)
				fmt.Println("请输入密码：")
				fmt.Scan(&passwd)
				fmt.Println("请输入年龄")
				fmt.Scan(age)
				fmt.Println("请输入地址")
				fmt.Scan(&address)
				sys.Register(name, passwd, age, address)
			} else if choice == "2" {
				fmt.Println("请输入用户名和密码")
				fmt.Println("请输入用户名：")
				fmt.Scan(&name)
				fmt.Println("请输入密码：")
				fmt.Scan(&passwd)
				sys.Login(name, passwd)
			} else {
				fmt.Println(sys.SystemName, "退出成功")
				break
			}
		}
	}
}

func (s *System) Register(name string, passwd string, age string, address string) {
	user := User{
		UserName:    name,
		UserPasswd:  passwd,
		UserAge:     age,
		UserAddress: address,
	}
	s.SystemUser[user.UserName] = user
	fmt.Println("注册成功！")

}

func (s System) Login(name string, passwd string) {
	user, ok := s.SystemUser[name]
	if !ok {
		fmt.Println("用户不存在！")
	} else {
		if user.UserPasswd == passwd {
			fmt.Println("登录成功，欢饮进入", s.SystemName)
		} else {
			fmt.Println("用户名和密码不匹配！")
		}
	}
}
